#!/usr/bin/python
# coding=utf-8
# from optparse import OptionParser
from scan_exec import web_dir_scan
import sys
import os

def inputdata():
    url = input("请输入你要渗透的target:")
    type = input("请输入目标的类型(default all):")
    thread_count = input("请输入线程数量:")
    try:
        if isinstance(url, str) and isinstance(type, str) and int(thread_count) < 125 :
            if type == 'php' or type == 'asp' or type == 'other'or type == 'all':
                suffix = url.rfind("/",len(url)-1,len(url))
                if suffix < 0:
                    url = url+"/"
                data = {'url':url,'type':type,'thread_count':thread_count,'filename':'./dictionary'}
                return data
            else:
                print('input error\n')
                inputdata()
        else:
            print('input error\n')
            inputdata()
    except:
        inputdata()


def reload():
    command = input("quit or renew,please input q or start:")
    if command == 'start':
        python = sys.executable
        os.execl(python, python, *sys.argv)

    if command == 'q':
        sys.exit(1)
    else:
        reload()

if __name__ == '__main__':

    print('''
                        ╔═══╗──────╔╗────────────────╔╗
            ║╔═╗║─────╔╝╚╗───────────────║║
            ║║─╚╬═╗╔══╬╗╔╝╔══╦╗╔╗╔╦══╦═╦═╝║
            ║║╔═╣╔╗╣╔╗║║║─║══╣╚╝╚╝║╔╗║╔╣╔╗║
            ║╚╩═║║║║╔╗║║╚╗╠══╠╗╔╗╔╣╚╝║║║╚╝║
            ╚═══╩╝╚╩╝╚╝╚═╝╚══╝╚╝╚╝╚══╩╝╚══╝

            ''')

    # fakeArgs = ['-f', 'file.txt', '-u', 'how are you']
    # parser = OptionParser(' -u <Target URL> -f <Dictionary file name> [-t <Thread_count>]')
    # parser.add_option('-u', '--url', dest='url', type='string', help='target url for scan')
    # parser.add_option('-f', '--file', dest='filename', type='string', help='dictionary filename')
    # parser.add_option('-t', '--thread', dest='count', type='int', default=10, help='scan thread_count')
    # (options, args) = parser.parse_args(fakeArgs)
    options = inputdata()
    # print(options)
    if options['url']:
        # start(options.url,options.filename,options.count)
        dirscan = web_dir_scan.DirScanMain(options)
        dirscan.start()
        reload()
        # parser.print_help()
